package com.mit.service.maintenance.dao.impl;

import java.util.List;

import com.mit.common.exception.NoRecordUpdateException;
import com.mit.common.maintenance.dto.FabricCatDTO;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.maintenance.dao.IFabricCatDAO;

public class FabricCatDAOImpl extends AbstractDAO implements IFabricCatDAO {

	@Override
	public FabricCatDTO createFabricCat(FabricCatDTO fabricCatDTO) {
		Integer id = (Integer)  getSqlMapClientTemplate().insert("insertFabricCat", fabricCatDTO);
		fabricCatDTO.setId(id);
		return fabricCatDTO;
	}

	@Override
	public FabricCatDTO updateFabricCat(FabricCatDTO fabricCatDTO)
			throws NoRecordUpdateException {
		int rs = getSqlMapClientTemplate().update("updateFabricCat", fabricCatDTO);
		if(rs == 0) {
			throw new NoRecordUpdateException("No fabric category records!");
		}
		return fabricCatDTO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FabricCatDTO> retrieveFabricCats(int organizationId) {
		return getSqlMapClientTemplate().queryForList("selectFabricCats", organizationId);
	}

}
